setwd("c:/test/Cousera/")

complete <- function(directory, id = 1:332) {
  nobs <- numeric()
  filename <- list.files(directory, full.names=TRUE)[id]
  for (x in filename) {
    tdata <- read.csv(x, header = TRUE)
    temdata <- subset(tdata, sulfate != "NA" & nitrate != "NA")
    temnobs <- sum(temdata$ID) / temdata$ID[1]
    nobs <- c(nobs, temnobs)
  }
  dataall <- data.frame(id, nobs)
  dataall
}

complete("specdata", 1)
complete("specdata", c(2, 4, 8, 10, 12))
complete("specdata", 30:25)
complete("specdata", 3)